/*
  spr-sdk: Statistical Pattern Recognition SDK
  Copyright (C) 2010 Marco Ambu

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _UTIL_RANK_H
#define	_UTIL_RANK_H

#include "util/Real.h"
#include <vector>

namespace util {

class Rank
{
  struct Element
  {
    Element(std::size_t id, util::Real value)
            : classId(id)
            , distance(value)
    {}

    bool operator==(const Element& other) const { return classId == other.classId; }
    bool operator!=(const Element& other) const { return classId != other.classId; }

    std::size_t classId;
    util::Real distance;
  };

  struct LessThanElement
  {
    bool operator()(const Element& a, const Element& b) {
        return a.distance < b.distance;
    }
  };

public:
  Rank(std::size_t numElements, std::size_t rank)
    : numElements_(numElements)
    , rank_(rank)
  {}

  void addElement(std::size_t classId, util::Real distance);
  bool result(std::size_t classId) const;
  
private:
  std::size_t numElements_;
  std::size_t rank_;
  std::vector<Element> elements_;
};

} // namespace util

#endif	// _UTIL_RANK_H
